package view.subwindosw;

import BaseClass.BaseSubFrame;

import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTextField;

import model.entity.Company;
import model.initializeEntity.IntCompany;
import view.main.Main;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.swing.JButton;

public class KeyInFrame extends BaseSubFrame {

	private JTextField PriceTxt;
	private JTextField DiscountTxt;
	private JTextField CashTxt;
	private JLabel label = new JLabel("廠商：");
	private JComboBox<String> CompanyBox = new JComboBox<String>();
	private JComboBox<String> MedicineBox = new JComboBox<String>();
	private JComboBox<String> YearBox = new JComboBox<String>();

	@SuppressWarnings("unchecked")
	public KeyInFrame() throws ClassNotFoundException, SQLException {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				new Main().setKeyin_windows(false);
			}
		});

		Initialize();
		setTitle("帳單");
		setBounds(100, 100, 626, 489);
		getContentPane().setLayout(null);

		label.setFont(new Font("新細明體", Font.PLAIN, 20));
		label.setBounds(39, 38, 71, 23);
		getContentPane().add(label);
		CompanyBox.setFont(new Font("新細明體", Font.PLAIN, 20));

		CompanyBox.setBounds(102, 35, 100, 29);
		getContentPane().add(CompanyBox);

		JLabel label_1 = new JLabel("藥品：");
		label_1.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_1.setBounds(226, 38, 71, 23);
		getContentPane().add(label_1);

		MedicineBox.setFont(new Font("新細明體", Font.PLAIN, 20));
		MedicineBox.setBounds(294, 35, 230, 29);
		getContentPane().add(MedicineBox);

		JLabel lbll = new JLabel("進貨日：");
		lbll.setFont(new Font("新細明體", Font.PLAIN, 20));
		lbll.setBounds(39, 87, 89, 23);
		getContentPane().add(lbll);

		YearBox.setFont(new Font("新細明體", Font.PLAIN, 20));
		YearBox.setModel(new DefaultComboBoxModel(new String[] { "103", "104",
				"105", "106", "107", "108", "109", "110", "111", "112", "113",
				"114", "115" }));
		YearBox.setBounds(123, 84, 55, 29);
		getContentPane().add(YearBox);

		JLabel label_2 = new JLabel("年");
		label_2.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_2.setBounds(182, 87, 55, 23);
		getContentPane().add(label_2);

		JComboBox MonBox = new JComboBox();
		MonBox.setModel(new DefaultComboBoxModel(new String[] { "01", "02",
				"03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
		MonBox.setFont(new Font("新細明體", Font.PLAIN, 20));
		MonBox.setBounds(207, 84, 53, 29);
		getContentPane().add(MonBox);

		JLabel label_3 = new JLabel("月");
		label_3.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_3.setBounds(268, 87, 29, 23);
		getContentPane().add(label_3);

		JComboBox comboBox = new JComboBox();
		comboBox.setFont(new Font("新細明體", Font.PLAIN, 20));
		comboBox.setModel(new DefaultComboBoxModel(new String[] { "01", "02",
				"03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
				"13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
				"23", "24", "25", "26", "27", "28", "29", "30", "31" }));
		comboBox.setBounds(294, 84, 55, 29);
		getContentPane().add(comboBox);

		JLabel label_4 = new JLabel("金額：");
		label_4.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_4.setBounds(39, 139, 71, 23);
		getContentPane().add(label_4);

		PriceTxt = new JTextField();
		PriceTxt.setFont(new Font("新細明體", Font.PLAIN, 20));
		PriceTxt.setBounds(102, 136, 161, 29);
		getContentPane().add(PriceTxt);
		PriceTxt.setColumns(10);

		JLabel label_5 = new JLabel("折讓：");
		label_5.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_5.setBounds(39, 182, 71, 23);
		getContentPane().add(label_5);

		DiscountTxt = new JTextField();
		DiscountTxt.setFont(new Font("新細明體", Font.PLAIN, 20));
		DiscountTxt.setColumns(10);
		DiscountTxt.setBounds(102, 178, 161, 29);
		getContentPane().add(DiscountTxt);

		JLabel label_6 = new JLabel("現金折扣：");
		label_6.setFont(new Font("新細明體", Font.PLAIN, 20));
		label_6.setBounds(39, 222, 100, 23);
		getContentPane().add(label_6);

		CashTxt = new JTextField();
		CashTxt.setFont(new Font("新細明體", Font.PLAIN, 20));
		CashTxt.setColumns(10);
		CashTxt.setBounds(141, 222, 161, 29);
		getContentPane().add(CashTxt);

		JButton btnNewButton = new JButton("確定");
		btnNewButton.setFont(new Font("新細明體", Font.PLAIN, 20));
		btnNewButton.setBounds(466, 397, 101, 29);
		getContentPane().add(btnNewButton);
		setLocationRelativeTo(null);

	}

	public void Initialize() throws ClassNotFoundException, SQLException {
		IntCompany comps = new IntCompany();
		Objects = null;
		InitializeCompany(CompanyBox, Objects);
	}

	public void InitializeCompany(JComboBox<String> c, List<Company> comps) {

		for (Company com : comps) {
			// System.out.println(com.toString());
			c.addItem(com.getComPanyName());
		}
	}
}
